//
//  TMNetworkConfig.m
//  Pods
//
//  Created by LIJUN on 16/8/24.
//
//

#import "TMNetworkConfig.h"

@interface TMNetworkConfig ()

@property (nonatomic, strong) NSMutableArray *accessoryDelegateArray;

@end

@implementation TMNetworkConfig

#pragma mark - Init & Dealloc

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.baseUrl = @"";
        self.maxConcurrentOperationCount = 4;
        self.requestTimeoutInterval = 30;
        self.securityPolicy = [AFSecurityPolicy defaultPolicy];
        self.accessoryDelegateArray = [NSMutableArray array];
    }
    return self;
}

#pragma mark - Public Method

- (void)addAccessory:(id<TMRequestAccessoryDelegate>)accessoryDelegate
{
    if (![_accessoryDelegateArray containsObject:accessoryDelegate]) {
        [_accessoryDelegateArray addObject:accessoryDelegate];
    }
}

- (void)removeAccessory:(id<TMRequestAccessoryDelegate>)accessoryDelegate
{
    if ([_accessoryDelegateArray containsObject:accessoryDelegate]) {
        [_accessoryDelegateArray removeObject:accessoryDelegate];
    }
}

#pragma mark - Static Method

+ (TMNetworkConfig *)sharedConfig
{
    static id sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

@end
